package bm.com.framework.common.resp;

import bm.com.framework.common.config.EnumCode;

import java.util.HashMap;

public class ResultVO extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResultVO put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public ResultVO() {
        put("code", 0);
        put("msg", "success");
        put("data",  null);
    }

    public static ResultVO success(Object obj) {
        ResultVO resultVO = new ResultVO();
        resultVO.put("code", EnumCode.CODE_SUCCESS);
        resultVO.put("msg","操作成功");
        resultVO.put("data",obj);
        return resultVO;
    }

    public static ResultVO success(String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.put("code",EnumCode.CODE_SUCCESS);
        resultVO.put("msg",msg);
        resultVO.put("data",null);
        return resultVO;
    }

    public static ResultVO success(int code,String str,Object obj) {
        ResultVO resultVO = new ResultVO();
        resultVO.put("code",code);
        resultVO.put("msg",str);
        resultVO.put("data",obj);
        return resultVO;
    }

    public static ResultVO error(int code, String msg,Object obj) {
        ResultVO r = new ResultVO();
        r.put("code", code);
        r.put("msg", msg);
        r.put("data", obj);
        return r;
    }

    public static ResultVO error(int code, String msg) {
        if(msg.isEmpty()){
            msg = "系统异常错误";
        }

        ResultVO r = new ResultVO();
        r.put("code", code);
        r.put("msg", msg);
        r.put("data", null);
        return r;
    }

    public static ResultVO error(String msg) {
        ResultVO r = new ResultVO();
        r.put("code", EnumCode.CODE_ERROR);
        r.put("msg", msg);
        r.put("data", null);
        return r;
    }

}
